#!/usr/bin/env python
# coding=utf-8
"""Base62进制编码和解码"""

CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"


def decode(base62):
    """
    62进制格式字符串解码为10进制
    :return: 10进制数
    """
    result = 0
    for c in base62:
        index = CHARS.index(c)
        result = index + result * 62
    return result


def encode(base10):
    """
    10进制编码为62进制格式字符串
    :return: 62进制格式字符串
    """
    result = ""
    tmp = base10
    while tmp > 0:
        mod = tmp % 62
        tmp = tmp // 62
        result = CHARS[mod] + result
    return result


if __name__ == '__main__':
    print(encode(104880564))
